Warn if length overflows. (#161520, Ian Wienand)
authorMatthias Clasen <mclasen@redhat.com>
Wed, 18 May 2005 14:46:14 +0000 (14:46 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 18 May 2005 14:46:14 +0000 (14:46 +0000)
2005-05-18  Matthias Clasen  <mclasen@redhat.com>

* gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
length overflows.  (#161520, Ian Wienand)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gdk/tmpl/properties.sgml
gdk/x11/gdkproperty-x11.c

index 7bd3876c2f2117a2f44d542726c7dae9d5321f2d..f4defc31b5871e26ace61f13bf4ae4f2f6ab1e6b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2005-05-18  Matthias Clasen  <mclasen@redhat.com>
 
+       * gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
+       length overflows.  (#161520, Ian Wienand)
+
        * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
        parameter names to make gtk-doc happy.
 
index 7bd3876c2f2117a2f44d542726c7dae9d5321f2d..f4defc31b5871e26ace61f13bf4ae4f2f6ab1e6b 100644 (file)
@@ -1,5 +1,8 @@
 2005-05-18  Matthias Clasen  <mclasen@redhat.com>
 
+       * gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
+       length overflows.  (#161520, Ian Wienand)
+
        * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
        parameter names to make gtk-doc happy.
 
index 7bd3876c2f2117a2f44d542726c7dae9d5321f2d..f4defc31b5871e26ace61f13bf4ae4f2f6ab1e6b 100644 (file)
@@ -1,5 +1,8 @@
 2005-05-18  Matthias Clasen  <mclasen@redhat.com>
 
+       * gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
+       length overflows.  (#161520, Ian Wienand)
+
        * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
        parameter names to make gtk-doc happy.
 
index 1eff73708bf5d8a46f82c75ac443241c23b7d53e..386145b78951444c922571253b281f18e384332f 100644 (file)
@@ -1,5 +1,7 @@
 2005-05-18  Matthias Clasen  <mclasen@redhat.com>
 
+       * gdk/tmpl/properties.sgml: Updates.
+
        * gtk/migrating-checklist.sgml: Add a section about named
        icons.
 
index dd8ba68dd306aa594015305944c9421ba5b9abac..dc63c5ac59accad2d3996ff4405f041748afc4f8 100644 (file)
@@ -42,6 +42,9 @@ data commonly stored in X window properties.
 
 </para>
 
+<!-- ##### SECTION Stability_Level ##### -->
+
+
 <!-- ##### STRUCT GdkAtom ##### -->
 <para>
 An opaque type representing a string as an index into a table
@@ -252,15 +255,14 @@ and %GDK_NONE will be stored in @actual_property_type.
 </para>
 <note>
 <para>
-The <function>XGetWindowProperty()</function>
-function that gdk_property_get()
-uses has a very confusing and complicated set of semantics.
+The XGetWindowProperty() function that gdk_property_get()
+uses has a very confusing and complicated set of semantics.  
 Unfortunately, gdk_property_get() makes the situation
 worse instead of better (the semantics should be considered
 undefined), and also prints warnings to stderr in cases where it
 should return a useful error to the program. You are advised to use 
-<function>XGetWindowProperty()</function>
-directly until a replacement function for gdk_property_get()
+XGetWindowProperty() directly until a replacement function for 
+gdk_property_get()
 is provided. 
 </para>
 </note>
@@ -273,18 +275,24 @@ is provided.
        be filled in, a warning will be printed to stderr
        and no data will be returned.
 @offset: the offset into the property at which to begin
-         retrieving data. (in 4 byte units!)
-@length: the length of the data to delete. (in bytes, but
-         the actual retrieved length will be the next
-         integer multiple multiple of four greater than 
-         this!)
+         retrieving data, in 4 byte units.
+@length: the length of the data to retrieve in bytes.  Data is
+         considered to be retrieved in 4 byte chunks, so @length 
+         will be rounded up to the next highest 4 byte boundary 
+         (so be careful not to pass a value that might overflow 
+          when rounded up).
 @pdelete: if %TRUE, delete the property after retrieving the
           data.
 @actual_property_type: location to store the actual type of 
                        the property.
-@actual_format: location to store the actual format of the data.
-@actual_length: location to store the length of the retrieved
-                data, in bytes.
+@actual_format: location to store the actual return format of the
+                data; either 8, 16 or 32 bits.
+@actual_length: location to store the length of the retrieved data, in
+                bytes.  Data returned in the 32 bit format is stored
+                in a long variable, so the actual number of 32 bit
+                elements should be be calculated via
+                @actual_length/sizeof(glong) to ensure portability to
+                64 bit systems.
 @data: location to store a pointer to the data. The retrieved
        data should be freed with g_free() when you are finished
        using it.
index 4069e018a7fc391d0a85ad861ae2592d333a1ed0..e1f5d77f0d5c85b98fbdb62e7f685811568d796e 100644 (file)
@@ -493,6 +493,7 @@ gdk_property_get (GdkWindow   *window,
   gint ret_format;
   gulong ret_nitems;
   gulong ret_bytes_after;
+  gulong get_length;
   gulong ret_length;
   guchar *ret_data;
   Atom xproperty;
@@ -521,9 +522,30 @@ gdk_property_get (GdkWindow   *window,
 
   ret_data = NULL;
   
+  /* 
+   * Round up length to next 4 byte value.  Some code is in the (bad?)
+   * habit of passing G_MAXLONG as the length argument, causing an
+   * overflow to negative on the add.  In this case, we clamp the
+   * value to G_MAXLONG.
+   */
+  get_length = length + 3;
+  if (get_length > G_MAXLONG)
+    {
+      g_warning ("gdk_property_get(): length value has wrapped in calculation "
+                "(did you pass G_MAXLONG?)");
+      get_length = G_MAXLONG;
+    }
+  /* To fail, either the user passed 0 or G_MAXULONG */
+  get_length = get_length / 4;
+  if (get_length == 0)
+    {
+      g_warning ("gdk_propery-get(): invalid length 0");
+      return FALSE;
+    }
+
   res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
                            GDK_WINDOW_XWINDOW (window), xproperty,
-                           offset, (length + 3) / 4, pdelete,
+                           offset, get_length, pdelete,
                            xtype, &ret_prop_type, &ret_format,
                            &ret_nitems, &ret_bytes_after,
                            &ret_data);